#ifndef SYSTEM_MANAGER_H
#define SYSTEM_MANAGER_H

#include "common.h"
#include "database/db_manager.h"  // 新增数据库依赖

typedef struct {
    event_loop_t *event_loop;
    data_pool_t *data_pool;
    config_manager_t *config;
    timer_manager_t *timer;
    db_manager_t *db_mgr;         // 新增数据库管理器
    bool initialized;
    bool running;
} system_manager_t;

// 系统管理器API
int system_manager_init(system_manager_t *manager);
int system_manager_start(system_manager_t *manager);
void system_manager_stop(system_manager_t *manager);
void system_manager_cleanup(system_manager_t *manager);

// 事件处理函数
void system_manager_handle_api_response(system_manager_t *manager, event_t *event);
void system_manager_handle_data_update(system_manager_t *manager, event_t *event);
void system_manager_handle_timer_trigger(system_manager_t *manager, event_t *event);
void system_manager_handle_data_check(system_manager_t *manager, event_t *event);
void system_manager_handle_db_update(system_manager_t *manager, event_t *event);  // 新增数据库更新处理

// 工具函数
void system_manager_setup_api_tasks(system_manager_t *manager);
void system_manager_setup_monitor_tasks(system_manager_t *manager);

// 数据库相关函数
int system_manager_backup_database(system_manager_t *manager, const char *backup_path);
int system_manager_restore_database(system_manager_t *manager, const char *backup_path);

#endif
